<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>客户采纳护理项目管理</title>
	<meta name="decorator" content="default"/>
	<script type="text/javascript">
		var buyCareId = "";
		$(document).ready(function() {			
			$("#contentTable tbody tr").click(function(){
				$("#contentTable tbody tr").removeClass("select_active");
				$(this).addClass("select_active");
			});
			$("#contentTable tbody tr:first-child").click();
		});
		
		 function buyCare(id){
			buyCareId = id;
	    	var name = $("#contentTable tbody tr.select_active .name").html();
	    	$("#buyCare h3").html(name);
			$('#buyCare').popup('open');
			$("#numerror").html("");
        }
	    
	    function putCash(){
	    	var num = $("#buyNum").val();
	    	if(num <= 0){
	    		$("#numerror").html("购买数量必须大于0");
	    		return;
	    	}
	    	var customerId = '${customerId}';
	    	var employeeId = $("#employeeId").val();
	    	$('#buyCare').popup('close');
	    	jQuery.ajax({  
		          type : 'POST',  
		          url : '${ctx}/expert/customerSolutionAndCare/add',  
		          data :{'csId': '${customerSolutionId}', 'cId':buyCareId, 'times': num, 'customerId': customerId, 'employeeId': employeeId},
		          success : function(data) {
		        	  showTip("添加成功");
		          },  
		          error : function(data) {  
		        	  showTip("添加失败");
		          }  
		    }); 
	    	$("#buyNum").val("1");
	    }
	</script>
</head>
<body>
	<div class="icon-buttons">
		<c:if test="${target == 'buy'}">
			<a data-role="button" data-inline="true" data-icon="back" data-iconpos="notext"  href="${ctx}/expert/customerSolution/manager?customerExamId=${customerExamId}">返回</a>
			<a data-role="button" data-inline="true" data-icon="check" data-iconpos="notext" href="${ctx}/cash/member/detail?id=${customerId}">去购物车付款</a>
		</c:if>
		<c:if test="${target == 'detail'}">
			<a data-role="button" data-inline="true" data-icon="back" data-iconpos="notext"  href="${ctx}/expert/customerSolution/list?customerExamId=${customerExamId}">返回</a>
		</c:if>
	</div>
	<c:if test="${target == 'buy'}">
		<nav data-role="navbar">
			<ul>
				<li><a href="${ctx}/expert/customerSolutionAndProduct/detail?customerSolutionId=${customerSolutionId}&target=buy">产品续买</a></li>
				<li><a class="ui-btn-active" href="${ctx}/expert/customerSolutionAndCare/detail?customerSolutionId=${customerSolutionId}&target=buy">护理续买</a></li>
			</ul>
		</nav>
	</c:if>
	<br/>
	<table id="contentTable" class="display">
		<thead><tr><th>护理名称</th><th>目标达成价</th>
			<th>到期日期</th>
			<c:if test="${target == 'buy'}">
				<th>操作</th>
			</c:if>
		</tr></thead>
		<tbody>
		<c:forEach items="${list}" var="customerSolutionAndCare">
			<tr id="${customerSolutionAndCare.storeCare.id}"> 
				<c:if test="${customerSolutionAndCare.storeCare.care_type == 0}">
					<td class="name">${customerSolutionAndCare.storeCare.care.name}</td>
					<td>${customerSolutionAndCare.storeCare.care.price}</td>
				</c:if>
				<c:if test="${customerSolutionAndCare.storeCare.care_type == 1}">
					<td class="name">${customerSolutionAndCare.storeCare.storeSelfCare.name}</td>
					<td>${customerSolutionAndCare.storeCare.storeSelfCare.price}</td>
				</c:if>
				<td>${fns:formatDate(customerSolutionAndCare.notifyDate, "yyyy-MM-dd")}</td>
				<c:if test="${target == 'buy'}">
					<td>
	    				<a data-role="button" data-inline="true" onclick="buyCare('${customerSolutionAndCare.storeCare.id}')">续买</a>
					</td>
				</c:if>
			</tr>
		</c:forEach>
		</tbody>
	</table>
	<div data-role="popup" id="buyCare" class="ui-corner-all">
		<div style="padding:20px;width:300px;">
			<label style="display:none;color:red;text-align:center;width:100%;"></label>
			<div class="ui-field-contain"><h3></h3></div>
			<div class="ui-field-contain">
				<label for="buyNum">护理次数：</label><input type="number" id="buyNum" placeholder="请输入护理次数" value="1">
				<label style="color:red" id="numerror"></label>
			</div>
			<div class="ui-field-contain">
				<label for="employeeId">服务专员：</label>
				<select id="employeeId" name="employeeId">   
				  	<c:forEach var="map" items="${fns:getEmployee()}">
					 	<option value='${map.key}'>  
					  		${map.value}  
						</option>   
				 	</c:forEach>
				</select> 
			</div>
			<input type="button" data-icon="check" onclick="putCash()" value="加入购物车">
		</div>
	</div>
</body>
</html>
